package simplenotessyncsrv;

import java.util.Calendar;

public class TaskObj {

    private Long TaskID;
    private Calendar CreationTime = Calendar.getInstance();
    private Calendar FinishTime = Calendar.getInstance();
    private String TaskText = "";
    private Boolean Tekuchka = false;
    private Boolean Done = false;
    private Calendar ChangedTime = Calendar.getInstance();

    public TaskObj(Long ID, Calendar CreationTime, Calendar FinishTime, String TaskText, Boolean TaskDone, Boolean Tekuchka, Calendar ChTime) {
        this.CreationTime = CreationTime;
        this.FinishTime = FinishTime;
        this.TaskText = TaskText;
        this.Tekuchka = Tekuchka;
        this.Done = TaskDone;
        this.TaskID = ID;
        this.ChangedTime = ChTime;
    }

    public TaskObj(String ID, String CreationTime, String FinishTime, String TaskText, String TaskDone, String Tekuchka, String ChTime) {
        this.TaskID = Long.valueOf(ID);
        this.CreationTime.setTimeInMillis(Long.valueOf(CreationTime));
        this.FinishTime.setTimeInMillis(Long.valueOf(FinishTime));
        this.TaskText = getStringFromHex(TaskText);
        this.Done = Boolean.valueOf(TaskDone);
        this.Done = Boolean.valueOf(Tekuchka);
        this.ChangedTime.setTimeInMillis(Long.valueOf(ChTime));
    }

    private static String getStringFromHex(String hexstr) {
        String str = "";
        String s = "";
        Integer ci = 0;
        char c = (char) 0;
        int i = 0;
        while (i < hexstr.length()) {
            if (!hexstr.substring(i, i + 1).equals("|")) {
                s = s + hexstr.substring(i, i + 1);
                i++;
            } else {
                ci = Integer.parseInt(s, 16);
                c = (char) ci.intValue();
                str = str + c;
                s = "";
                i++;
            }
        }
        return str;
    }

    @Override
    public String toString() {
        return TaskText;
    }

    public void setCreationTime(Calendar CreationTime) {
        this.CreationTime = CreationTime;
    }

    public Calendar getCreationTime() {
        return CreationTime;
    }

    public void setFinishTime(Calendar FinishTime) {
        this.FinishTime = FinishTime;
    }

    public Calendar getFinishTime() {
        return FinishTime;
    }

    public void setTaskText(String TaskText) {
        this.TaskText = TaskText;
    }

    public String getTaskText() {
        return TaskText;
    }

    public void setDone(Boolean Done) {
        this.Done = Done;
    }

    public Boolean getDone() {
        return Done;
    }

    public Boolean getTekuchka() {
        return Tekuchka;
    }

    public void setTekuchka(Boolean Tekuchka) {
        this.Tekuchka = Tekuchka;
    }

    public Calendar getChangedTime() {
        return ChangedTime;
    }

    public void setChangedTime(Calendar ChangedTime) {
        this.ChangedTime = ChangedTime;
    }

    public Long getTaskID() {
        return TaskID;
    }

    public void setTaskID(Long TaskID) {
        this.TaskID = TaskID;
    }
}
